<?php

include "../../../lib/start.php";

ini_set("display_errors", "1");

check_session();
check_permission(DOC_PERM);

if(!isset($_REQUEST['cls']))
	$_REQUEST['cls'] = $_SESSION['__classe__']->get_ID();

$sel_classe = "SELECT classi.*, sedi.nome AS sede_des FROM classi, sedi WHERE classi.id_classe = ".$_REQUEST['cls']." AND classi.sede = sedi.id_sede";
$res_classe = $db->execute($sel_classe);
$current_class = new Classe($res_classe->fetch_assoc());
$_SESSION['__classe__'] = $current_class;

$sel_alunni = "SELECT id_alunno, cognome, nome FROM alunni WHERE alunni.id_classe = ".$_REQUEST['cls']." ORDER BY cognome, nome";
$res_alunni = $db->execute($sel_alunni);

$sel_registro = "SELECT id_reg, ingresso, uscita, data FROM reg_classi WHERE id_classe = ".$_SESSION['__classe__']->get_ID()." AND id_anno = ".$_SESSION['__current_year__']->get_ID()." AND data = '".date("Y-m-d")."'";
$res_registro = $db->execute($sel_registro);
$_SESSION['registro'] = $res_registro->fetch_assoc();

if(date("N", strtotime($_SESSION['registro']['data'])) == 1)
	$data = date("Y-m-d", strtotime($_SESSION['registro']['data']." -2 days"));
else
	$data = date("Y-m-d", strtotime($_SESSION['registro']['data']." -1 days"));
while(in_array($data, $holydays) || (date("N", strtotime($data)) == 7)){
	$data = date("Y-m-d", strtotime($data." -1 days"));
}

header("Content-Type: text/html; charset=utf-8");
header("Vary: Accept-Encoding");

include "today.html.php";

?>